package io.jpress.module.article.flowable.delegate;

import com.jfinal.aop.Inject;
import io.jpress.core.flowable.AutoLoadServiceTaskDelegate;
import io.jpress.module.article.model.ArticleFlowStatus;
import io.jpress.module.article.service.ArticleFlowStatusService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;

@AutoLoadServiceTaskDelegate(title = "拒绝发布文章",type = "article",order = 2)
public class RejectPublishArticleDelegate implements JavaDelegate {

    @Inject
    private ArticleFlowStatusService articleFlowStatusService;


    @Override
    public void execute(DelegateExecution execution) {
        ArticleFlowStatus flowStatus = articleFlowStatusService.findByProcessInstanceId(execution.getProcessInstanceId());
        if (flowStatus != null && !flowStatus.isFinished()) {
            flowStatus.setStatus(ArticleFlowStatus.STATUS_REFUSE);
            articleFlowStatusService.update(flowStatus);
        }
    }
}
